package com.backend.controller.teacher;

import com.backend.common.result.Result;
import com.backend.pojo.vo.LeaveRequestVO;
import com.backend.service.examineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/examine")
@CrossOrigin
public class examineController {
    @Autowired
    private examineService examineService;

    /*请假查询*/
    @GetMapping("/getLeaves")
    public Result<List<LeaveRequestVO>> getLeaves() {
        List<LeaveRequestVO> list = examineService.getLeaves();
        log.info("查询请假学生名单：{}",list);
        return Result.success(list);
    }

    /*审核请假*/
    @PutMapping("/{stuId}")
    public Result examineLeave(@PathVariable String stuId) {
        log.info("审核请假：{}",stuId);
        examineService.examineLeave(stuId);
        return Result.success();
    }

    /*根据id查看请假单详情*/
    @GetMapping("/{stuId}")
    public Result<LeaveRequestVO> getById(@PathVariable String stuId) {
        log.info("根据id查看请假单详情：{}",stuId);
        LeaveRequestVO leaveRequestVO = examineService.getById(stuId);
        return Result.success(leaveRequestVO);
    }

    /*打回请假单*/
    @PostMapping("/{stuId}")
    public Result sendBack(@PathVariable String stuId) {
        log.info("根据学生id打回请假单：{}",stuId);
        examineService.sendBack(stuId);
        return Result.success();
    }

    /*根据id删除请假单*/
    @DeleteMapping("/{stuId}")
    public Result delete(@PathVariable String stuId) {
        log.info("根据学生id删除请假单：{}",stuId);
        examineService.deleteById(stuId);
        return Result.success();
    }

    /*根据条件搜索请假单信息*/
    @GetMapping("/search/{condition}")
    public Result<List<LeaveRequestVO>> searchByCondition(@PathVariable String condition) {
        log.info("根据查询栏条件查询请假单：{}",condition);
        List<LeaveRequestVO> leaveRequestVO =  examineService.getByCondition(condition);
        return Result.success(leaveRequestVO);
    }
}
